using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class forums_controls_misc_Pager : System.Web.UI.UserControl
{
    public string HeaderText
    {
        get
        {
            return (string)ViewState["HeaderText"];
        }
        set
        {
            ViewState["HeaderText"] = value;
        }
    }

    public string SeparatorText
    {
        get
        {
            return (string)ViewState["SeparatorText"];
        }
        set
        {
            ViewState["SeparatorText"] = value;
        }
    }

    public string FooterText
    {
        get
        {
            return (string)ViewState["FooterText"];
        }
        set
        {
            ViewState["FooterText"] = value;
        }
    }

    public string UrlFormat
    {
        get
        {
            return (string)ViewState["UrlFormat"];
        }
        set
        {
            ViewState["UrlFormat"] = value;
        }
    }

    public int TotalPages
    {
        get
        {
            int totalPages;
            if (ViewState["TotalPages"] != null && Int32.TryParse(ViewState["TotalPages"].ToString(), out totalPages))
            {
                return totalPages;
            }
            else
            {
                return 0;
            }
        }
        set
        {
            ViewState["TotalPages"] = value;
        }
    }

    public int CurrentPage
    {
        get
        {
            int currentPage;
            if (ViewState["currentPage"] != null && Int32.TryParse(ViewState["currentPage"].ToString(), out currentPage))
            {
                return currentPage;
            }
            else
            {
                return 1;
            }
        }
        set
        {
            ViewState["currentPage"] = value;
        }
    }

    public int MaximumPages
    {
        get
        {
            int maxPages;
            if (ViewState["MaximumPages"] != null && Int32.TryParse(ViewState["MaximumPages"].ToString(), out maxPages))
            {
                return maxPages;
            }
            else
            {
                return 10;
            }
        }
        set
        {
            ViewState["MaximumPages"] = value;
        }
    }

    protected void Page_PreRender(object sender, EventArgs e)
    {
        rptPager.DataSource = Helpers.PageNumberHelper.GetPages(TotalPages, CurrentPage, MaximumPages);
        rptPager.DataBind();
    }
}
